let api = require('../../http.js/api.js')
let util = require('../../http.js/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // banner
    imgUrls: [
      'https://topic.camel.com.cn/module/wap_index_focus_201709/7645c28f-9674-49f0-8490-dca3f6237496.jpg?d=1',
      'https://topic.camel.com.cn/module/wap_index_focus_201709/cb445730-dda3-466e-ab17-60f1f6ca1cb7.jpg',
      'https://topic.camel.com.cn/module/wap_index_focus_201709/92b890bb-7182-4ba4-8bc7-3ffd7ebbcf1c.jpg'
    ],
    indicatorDots: true,
    indicatorColor: '#fff',
    indicatorActiveColor: '#d2ab44',
    autoplay: true,
    interval: 5000,
    duration: 1000,
    circular: true,

    countdown: '',
    // 目标日期
    endDate: '2019-11-11',

    // 顶部标题
    arrTitle: ['推荐', '户外', '运动', '男鞋', '女鞋', '童装', '男装', '瑜伽'],
    index: 0,
    currentTab: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    that.countTime();
  },

  changColor(e) {
    var that = this;
    this.setData({
      currentTab: e.currentTarget.id
    })
  },

  countTime() {
    var that = this;
    var nowTime = new Date().getTime();
    var endDate = new Date(that.data.endDate).getTime();
    var endTime = endDate - nowTime;
    var d, h, m, s;
    if (endTime > 0) {
      d = Math.floor(endTime / 1000 / 60 / 60 / 24);
      h = Math.floor(endTime / 1000 / 60 / 60 % 24);
      m = Math.floor(endTime / 1000 / 60 % 60);
      s = Math.floor(endTime / 1000 % 60);
      s = s < 10 ? "0" + s : s;
      m = m < 10 ? "0" + m : m;
      h = h < 10 ? "0" + h : h;
      that.setData({
        countdown: h + ":" + m + ":" + s,
      })
      // 倒计时
      setTimeout(that.countTime, 100);
    } else {
      that.setData({
        countdown: '00:00:00'
      })
    }
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})